/**
 * 
 */
package com.thinkbiganalytics.security.rest.model;

/*-
 * #%L
 * kylo-security-rest-model
 * %%
 * Copyright (C) 2017 ThinkBig Analytics
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import java.util.HashSet;
import java.util.Set;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

/**
 *
 */
@JsonInclude(Include.NON_EMPTY)
@JsonIgnoreProperties(ignoreUnknown = true)
public class RoleMembershipChange {
    public enum ChangeType {ADD, REMOVE, REPLACE}

    private ChangeType change;
    private String roleName;
    private Set<String> users = new HashSet<>();
    private Set<String> groups = new HashSet<>();

    public RoleMembershipChange() {
    }

    public RoleMembershipChange(ChangeType change, String roleName) {
        super();
        this.change = change;
        this.roleName = roleName;
    }
    
    public RoleMembershipChange(ChangeType change, RoleMembership membership) {
        super();
        this.change = change;
        this.roleName = membership.getRole().getSystemName();
        membership.getUsers().forEach(u -> this.users.add(u.getSystemName()));
        membership.getGroups().forEach(g -> this.groups.add(g.getSystemName()));
    }

    public ChangeType getChange() {
        return change;
    }

    public void setChange(ChangeType change) {
        this.change = change;
    }

    public String getRoleName() {
        return roleName;
    }

    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }

    public Set<String> getUsers() {
        return users;
    }

    public Set<String> getGroups() {
        return groups;
    }

    public void addGroup(String groupName) {
        groups.add(groupName);
    }

}
